<template>
  <dialog-form style="min-width: 700px;" v-model="value" title="代码测试结果" :confirm-button="true"  @confirm="value = false">
    <template #content>
      <div v-if="codeResult.runResult && codeResult.runResult.isCompiled">
        <span>编译失败</span>
        <pre style="color: darkred; background-color: #f1f1f1;">
          <span v-for="(item,index) in codeResult.compileResult" :key="index">
            {{ item }}
          </span>
        </pre>
      </div>
      <div v-else-if="codeResult.runResult">
        <div style="display: flex; justify-content: space-between; width: 100%">
          <span>测试用例数：{{ codeResult.runResult.count }} </span>
          <el-tag v-if="codeResult.runResult.pass_count === codeResult.runResult.count"
                  type="success">
            全部通过{{ codeResult.pass_count }}
          </el-tag>
          <el-tag v-else type="danger">
            未通过
          </el-tag>
        </div>
        <el-table :data="codeResult.runResult.result" stripe style="width: 100%">
          <el-table-column label="用例">
            <template #default="scope">
                测试用例{{scope.$index+1}}
            </template>
          </el-table-column>
          <el-table-column prop="result" label="结果" width="180" >
            <template #default="scope">
              <el-tag v-if="scope.row && scope.row.result===1">{{resultMap[scope.row.result]}}</el-tag>
              <el-tag v-else-if="scope.row && scope.row.result===2" type="warning">{{resultMap[scope.row.result]}}</el-tag>
              <el-tag v-else-if="scope.row && scope.row.result!==0" type="danger">{{resultMap[scope.row.result]}}</el-tag>
              <el-tag v-else-if="scope.row && scope.row.result===0" type="success">{{resultMap[scope.row.result]}}</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="timeused" label="用时ms" width="180" />
          <el-table-column prop="memoryused" label="内存bit" />
        </el-table>
      </div>
    </template>
  </dialog-form>
</template>

<script>
import DialogForm from '@/components/dialog/DialogForm'
export default {
  name: 'code-result',
  props: {
    modelValue: { default: false },
    codeResult: {}
  },
  computed: {
    value: {
      get () {
        return this.modelValue
      },
      set (value) {
        this.$emit('update:modelValue', value)
      }
    }
  },
  components: { DialogForm },
  setup () {
    return {
      haha: '',
      resultMap: [
        '通过',
        '格式错误',
        '运行超时',
        '内存超限',
        '答案错误',
        '运行时错误',
        '输出结果超限',
        '编译错误',
        '系统错误'
      ]
    }
  },
  methods: {
    getMsg () {
    }
  }
}
</script>

<style scoped>

</style>
